﻿using System;
using System.Data;

namespace HippoMapper.Entity.Base
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple=false)]
    public class PropertyInfoAttribute : Attribute {

        #region 构造函数

        private PropertyInfoAttribute()
        {
            IsKey = false;

            DataType = DbType.String;
        }

        public PropertyInfoAttribute(string field)
            : this()
        {

            Field = field;
        }

        #endregion

        #region 属性

        /// <summary>
        /// 数据库字段
        /// </summary>
        public string Field { get; set; }

        /// <summary>
        /// 是否为主键
        /// </summary>
        public bool IsKey { get; set; }

        /// <summary>
        /// 字段数据类型
        /// </summary>
        public DbType DataType { get; set; }

        /*
        /// <summary>
        /// 字段值
        /// </summary>
        public object Value { get; set; }
        */

        /// <summary>
        /// 参数名称
        /// </summary>
        public string ParamName {
            get {
                return string.Format("@{0}{1}", Field.Substring(1, 1).ToLower(), Field.Substring(2));
            }
        }

        /// <summary>
        /// 对应的属性字符串表达
        /// </summary>
        public string PropertyString { get; set; }

        #endregion
    }
}
